module.exports = async (ctx, next) => {
	await next()
		.then(() => {
			console.log("true", ctx.status);
			if (ctx.status === 200) {
				ctx.body = {
					message: "成功",
					code: 200,
					body: ctx.body,
					status: true,
				};
			} else if (ctx.status === 201) {
			} else if (ctx.status === 401) {
				ctx.body = {
					message: "请重新登陆",
					code: ctx.status,
					body: ctx.body,
					status: true,
				};
			} else if (ctx.status === 404) {
				ctx.body = {
					message: "404 没有此资源",
					code: ctx.status,
					body: ctx.body,
					status: true,
				};
			} else if (ctx.status === 503) {
				ctx.body = {
					message: "请求执行异常",
					code: ctx.status,
					body: ctx.body,
					status: true,
				};
			} else {
				console.log(ctx.status, ctx.body);
				ctx.body = {
					message: ctx.body || ctx.body.msg || "接口异常,请重试",
					code: ctx.status,
					body: ctx.body.msg || "接口请求失败",
					status: false,
				};
			}
		})
		.catch((err) => {
			console.log("false", err);
			ctx.body = err;
			if (err.message === "jwt expired") {
				ctx.status = 401;
				ctx.body = {
					code: 401,
					status: false,
					message: "登陆过期,请重新登陆",
				};
			} else {
				ctx.status = 500;
				ctx.body = {
					code: -1,
					status: false,
					message: err.message,
				};
			}
		});
};
